//comment_submit:校验提交的评论
var codeResult = null;
var isFlag = false;
function postComment()
{
	var author = document.getElementById('author');
	var msgContent = document.getElementById('commentContent');
	var email = document.getElementById('mail');
	var site = document.getElementById('website');
	var button = document.getElementById('submit_button');
	var code = document.getElementById('code');
	if (author.value == "")
	{
		alert("请填写name");
		author.focus();
		return false;
	}
	if (author.value.length > 20)
	{
		author("name不能超过20个字符");
		author.focus();
		return false;
	}
	if (msgContent.value.length > 500)
	{
		alert("评论内容不能超过500个字符");
		msgContent.focus();
		return false;
	}
	if (email.value == "") {
		alert('请输入mail!');
		email.focus();
		return false;
	}
	if (email.value.length > 50) {
		alert('mail请不要超过50个字符!');
		email.focus();
		return false;
	}
	if (email.value != "" && !validEmail(email.value))
	{
		alert("mail输入格式不正确");
		email.focus();
		return false;
	}
	if (msgContent.value == "" || msgContent.value.length == 0)
	{
		alert("你未填写任何留言内容！");
		msgContent.focus();
		return false;
	}
	if (site.value.length > 50)
	{
		alert("链接不能超过50个字符");
		site.focus();
		return false;
	}
	if (site.value == "" || site.value == "http://")
	{
		site.value="#";
	}
	if (code.value == "" || code.value.length == 0) {
		alert('请输入验证码');
		code.focus();
		return false;
	}
	/*
	if (code.value != codeResult) {
		alert('计算结果不正确');
		code.focus();
		return false;
	}
	*/
	if (isFlag == true) {
		alert('请不要重复提交');
		return;
	}
	msgContent.value = filterHtml(msgContent.value);
	document.comment_form.submit();
	//document.comment_form.reset();
	isFlag = true;
	button.value = "Submit..."
}

//validEmail:校验email格式是否正确
function validEmail(email)
{
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	return re.test(email);
}
//filterHtml:过滤html中的js代码
function filterHtml(html)
{
   var fHtml = html.replace(/<script.*?>(.|\s|\r|\r\n)*?<\/script>/gim,"");
   return fHtml;
}
//过滤html标签
function setContent(str) {
	str = str.replace(/<\/?[^>]*>/g,''); //去除HTML tag
	str.value = str.replace(/[ | ]*\n/g,'\n'); //去除行尾空白
	str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
	return str;
	}
//reply:回复评论时，初始化评论内容，及评论对象
function reply(anchor, guest)
{
	var replyId = document.getElementById('replyId');
	replyId.value = anchor;
	var msg = "<a href=\"#comment-"+anchor+"\">@"+guest+"</a>";
	var msgContent = document.getElementById('commentContent');
	msgContent.value = msg;
	msgContent.focus();
}
function quote(anchor, guest)
{
	var quoteText = document.getElementById(anchor).innerHTML;
	quoteText = "引用"+guest+"<blockquote>"+quoteText+"</blockquote>";
	var msgContent = document.getElementById('commentContent');
	msgContent.value = msgContent.value + quoteText;
	msgContent.focus();
}
function code() {
	var num1 = document.getElementById("num1");
	var num2 = document.getElementById("num2");
	var num11 = Math.floor(Math.random() * 10);
	var num22 = Math.floor(Math.random() * 10);
	num1.innerHTML = num11;
	num2.innerHTML = num22;
	codeResult = num11 + num22;
}